package com.offcn.service.Impl;

import com.offcn.dao.UserDao;
import com.offcn.dao.impl.UserDaoImpl;
import com.offcn.entity.User;
import com.offcn.service.UserService;
import com.offcn.utils.Page;

public class UserServiceImpl implements UserService {
    //获取到的user继续交给dao层传至数据库查询，获取user对象
    UserDao userDao = new UserDaoImpl();
    @Override
    public User getUser(String username) {
        User user = userDao.getUser(username);
        return user;
    }

    @Override
    public void addUser(User user1) {
        userDao.addUser(user1);
    }


    @Override
    public Page<User> getUserList(String pageNo) {
        //将获取到的pageNo进行数据转换
        Integer pageno = Integer.parseInt(pageNo);
        return userDao.getUserList(pageno);
    }

    @Override
    public User getUserById(String id) {
        //进行数据转换
        Integer sid = 0;
        try {
            sid = Integer.parseInt(id);
        } catch (Exception e) {

        }
        return userDao.getUserById(sid);
    }


    //修改数据
    @Override
    public void updateUser(String id, String username, String password, String email) {
        //将id进行数据转换
        Integer sid = Integer.parseInt(id);
        //将数据封装成User对象
        User user = new User(sid, username, password, email);
        userDao.updateUser(user);
    }


    //删除数据
    @Override
    public void deleteUserById(String id) {
        //将id进行转换
        int sid = Integer.parseInt(id);
        userDao.deleteUserById(sid);
    }
}
